#coding=utf-8
import time  
from selenium import webdriver  
from selenium.webdriver.common.action_chains import ActionChains

from bs4 import BeautifulSoup
import math
import random
import numpy as np
import os
import xlrd
import pandas as pd
import requests
import re



'''
def get_html(url):
    headers = {
        'User-Agent':'Mozilla/5.0(Macintosh; Intel Mac OS X 10_11_4)\
        AppleWebKit/537.36(KHTML, like Gecko) Chrome/52 .0.2743. 116 Safari/537.36'
 
    }     #模拟浏览器访问
    response = requests.get(url,headers = headers)       #请求访问网站
    html = response.text       #获取网页源码
    return html                #返回网页源码
 
soup = BeautifulSoup(get_html('https://admin.paypal.com/'), 'lxml')   #初始化BeautifulSoup库,并设置解析器
print(get_html('https://admin.paypal.com'))
for li in soup.find_all(name='li'):         #遍历父节点
        for a in li.find_all(name='a'):     #遍历子节点
            if a.string==None:
                pass
            else:
                print(a.string)      #输出结果
'''



def batch_update(account_id=1416475804505026361, MCC=5331):
        
    driver = webdriver.Chrome(r'C:\Users\guosu\Desktop\crawlers\chromedriver_win32\chromedriver.exe')
    elem = driver.get('https://admin.paypal.com')
    elem = driver.find_element_by_id("id_accountNo")
    elem.send_keys(account_id)
    elem_search = driver.find_element_by_class_name("findUserSearch").click()

    def get_info(account_id=1314040086950293611):
        elem = driver.get('https://admin.paypal.com/cgi-bin/admin?node=loaduserpage_home&add_pagepart=admin_restrictions_new&account_number='+str(account_id)+'#admin_restrictions_new')
        try:
            elem_search = driver.find_element_by_id("show_linitations_url").click()
        except Exception as e:
            print(e, " \nthere should be no limitation ever on this account")
        driver.execute_script("window.scrollTo(0, (document.body.scrollHeight)/3);")
        status = driver.page_source

        #service_log = status.find('EE LE')
        result = status.find('EE Legal')
        result1 = status.find('AUP No')
        service_log = ((result==-1)&(result1==-1) and "没有" or "有的")
        print(str(account_id), "'s EE Legal is ", service_log)

        '''
        # show current limitations
        service_log = status[status.find('<!-- BEGIN LIMITATIONS -->'):status.find('Show Past Limitations')]
        filtered_service_log = re.findall(".*<b>(.*)</b>.*",service_log)
        print(str(account_id)+'current result is\n')
        for log in filtered_service_log:
            print(log)

        # show past limitations
        service_log = status[status.find('Show Past Limitations'):status.find('<!-- END LIMITATIONS -->')]
        filtered_service_log = re.findall(".*<b>(.*)</b>.*",service_log)
        print(str(account_id)+'past result is\n')
        for log in filtered_service_log:
            print(log)
        '''

    # 把需要查询的号码放在accounts列表里。
    accounts=[1857606088031069189,2165655780757226242,1722676198262212109,2086667025921101461,1940460085651644167,1930468921748176158,2140817975875024490,1538044790816904504,1381282115563312491,1191429221823955619,2292111464099547694,1594230992302964966,1998803294374740205,2167763264320980795,2087612995471696928,2118283440818262481,1844500359546708838,1309705104991170017,2265784242262143658,1960965552362017205,1249253556919043055,2197377617841285222,1187655277517355543,2199693565418703582,2228341647254970840,1161994506812713636,2179873860352260536,1567476021938374326,1243125118486130400,2058539169124478872,1686952017261877897,1875651042830958157,1307249820696525049,1930081501580170867,1943402942752090942,2040679020261959580,1467449854894378549,1478770364616077083,1542846683114424744,1866121543902772456,2258610703963399132,1324710157424078087,1568472506563730476,1481180947690965238,2110311555987397293,1984202044216359456,1630353462519121493,1276246279099725215,1841609928018418933,1371090981795375689,1422924071679242090,1376592343198043894,2078799134353198636,1918596151661268900,2302380911675366275,1240667183495127545,1661066681155072506,2051435793633086087,2272347160915257807,1643934939267364305,
]

    for account in accounts:
        get_info(account)

    driver.quit()

batch_update()
